/**
 * Created by Eclipse. User: lyn Date: 2008-06-11 Time: 16:45:11 分页模型 To change
 * this template use File | Settings | File Templates.
 */
package com.jwb.pub.model;

public class Page
{
	
	/** the name of Entity Name */
	private String entityName;
	
	/** the number of every page */
	private int everyPageCnt;
	
	/** the total page number */
	private int totalPages;
	
	/** the total record number */
	private int totalRecords;
	
	/** the number of current page */
	private int currentPageNbr;
	
	/** display start page */
	private int firstPage;
	
	/** display end page */
	private int lastPage;
	
	/** the pages number of every display */
	private int dispPages;
	
	public Page()
	{
		this.entityName = "";
		this.everyPageCnt = Integer.parseInt("10");
		this.totalPages = 0;
		this.totalRecords = 0;
		this.currentPageNbr = 1;
		this.firstPage = 1;
		this.lastPage = 1;
		this.dispPages = Integer.parseInt("5");
	}
	
	public Page(int everyPageCnt)
	{
		this.entityName = "";
		this.everyPageCnt = everyPageCnt;
		this.totalPages = 0;
		this.totalRecords = 0;
		this.currentPageNbr = 1;
		this.firstPage = 1;
		this.lastPage = 1;
		this.dispPages = Integer.parseInt("5");
	}
	
	public Page(String entityName, int everyPageCnt, int totalPages,
			int totalRecords, int currentPageNbr, int firstPage, int lastPage,
			int dispPages)
	{
		super();
		this.entityName = entityName;
		this.everyPageCnt = everyPageCnt;
		this.totalPages = totalPages;
		this.totalRecords = totalRecords;
		this.currentPageNbr = currentPageNbr;
		this.firstPage = firstPage;
		this.lastPage = lastPage;
		this.dispPages = dispPages;
	}
	
	public void formatPage()
	{
		
		this.totalPages = (int) Math.ceil((double) this.totalRecords
				/ this.everyPageCnt);
		if (this.totalPages == 0)
		{
			this.totalPages = 1;
			this.currentPageNbr = 1;
			this.firstPage = 1;
			this.lastPage = 1;
		}
		else
		{
			if (this.currentPageNbr < 1)
			{
				this.currentPageNbr = 1;
			}
			if (this.currentPageNbr > this.totalPages)
			{
				//修改 往后翻页就取不到数据了
				this.currentPageNbr = this.totalPages;
			}
			this.firstPage = ((int) Math.ceil((double) this.currentPageNbr
					/ this.dispPages) - 1)
					* this.dispPages + 1;
			if (this.totalPages < (int) Math.ceil((double) this.currentPageNbr
					/ this.dispPages)
					* this.dispPages)
			{
				this.lastPage = this.totalPages;
			}
			else
			{
				this.lastPage = (int) Math.ceil((double) this.currentPageNbr
						/ this.dispPages)
						* this.dispPages;
			}
		}
	}
	
	public String getEntityName()
	{
		return entityName;
	}
	
	public void setEntityName(String entityName)
	{
		this.entityName = entityName;
	}
	
	public int getEveryPageCnt()
	{
		return everyPageCnt;
	}
	
	public void setEveryPageCnt(int everyPageCnt)
	{
		this.everyPageCnt = everyPageCnt;
	}
	
	public int getTotalPages()
	{
		return totalPages;
	}
	
	public void setTotalPages(int totalPages)
	{
		this.totalPages = totalPages;
	}
	
	public int getTotalRecords()
	{
		return totalRecords;
	}
	
	public void setTotalRecords(int totalRecords)
	{
		this.totalRecords = totalRecords;
	}
	
	public int getCurrentPageNbr()
	{
		return currentPageNbr;
	}
	
	public void setCurrentPageNbr(int currentPageNbr)
	{
		this.currentPageNbr = currentPageNbr;
	}
	
	public int getFirstPage()
	{
		return firstPage;
	}
	
	public void setFirstPage(int firstPage)
	{
		this.firstPage = firstPage;
	}
	
	public int getLastPage()
	{
		return lastPage;
	}
	
	public void setLastPage(int lastPage)
	{
		this.lastPage = lastPage;
	}
	
	public int getDispPages()
	{
		return dispPages;
	}
	
	public void setDispPages(int dispPages)
	{
		this.dispPages = dispPages;
	}
	
	public void printPages()
	{
		System.out.println("entityName=" + entityName);
		System.out.println("everyPageCnt=" + everyPageCnt);
		System.out.println("totalPages=" + totalPages);
		System.out.println("totalRecords=" + totalRecords);
		System.out.println("currentPageNbr=" + currentPageNbr);
		System.out.println("firstPage=" + firstPage);
		System.out.println("lastPage=" + lastPage);
		System.out.println("dispPages=" + dispPages);
		;
	}
	
}
